package GUI;

import javax.swing.JPanel;
import java.awt.SystemColor;
import javax.swing.JLabel;
import java.awt.Font;
import java.awt.Color;

import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JButton;

import Client.BusinessImplements;
import Controler.Delete_Autho_controler;
import Controler.Delete_User_controler;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.border.LineBorder;
/**
   * @author Lucie
 * Class name Delete_User_panel
 * extend  Abstract_Jpanel
 * purpose: this panel get User id from the user and call the controller 
 * to delete this user
 */
public class Delete_User_panel extends Abstract_Jpanel {
	private JTextField textField_id;

	/**
	 * Create the panel.
	 */
	public Delete_User_panel() {
		setLayout(null);
		
		JPanel panel = new JPanel();
		panel.setBorder(new LineBorder(SystemColor.activeCaption, 6));
		panel.setBackground(SystemColor.inactiveCaption);
		panel.setBounds(35, 55, 550, 256);
		add(panel);
		panel.setLayout(null);
		
		JPanel panel_1 = new JPanel();
		panel_1.setBorder(new LineBorder(SystemColor.control, 6));
		panel_1.setBackground(new Color(220, 220, 220));
		panel_1.setBounds(38, 36, 466, 184);
		panel.add(panel_1);
		panel_1.setLayout(null);
		
		JLabel lblUserId = new JLabel("User ID:");
		lblUserId.setBounds(34, 34, 50, 17);
		panel_1.add(lblUserId);
		lblUserId.setFont(new Font("Tahoma", Font.PLAIN, 14));
		
		textField_id = new JTextField();
		textField_id.setBounds(115, 34, 182, 20);
		panel_1.add(textField_id);
		textField_id.setColumns(10);
		
		JLabel lblChooseIdOf = new JLabel("choose id of the user that you like  to delete");
		lblChooseIdOf.setBounds(34, 71, 325, 20);
		panel_1.add(lblChooseIdOf);
		lblChooseIdOf.setForeground(Color.RED);
		lblChooseIdOf.setFont(new Font("Segoe Print", Font.PLAIN, 13));
		
		JLabel lblDeleteUser = new JLabel("Delete User");
		lblDeleteUser.setForeground(new Color(25, 25, 112));
		lblDeleteUser.setFont(new Font("MV Boli", Font.BOLD, 30));
		lblDeleteUser.setBounds(46, 11, 307, 33);
		add(lblDeleteUser);
		/*
		  *btnDelete=When you click this button you will call delete_User( textField_id.getText())
		 * a method of the controller of this panel if this method return true we will
		 * call the methods of this class next_screen_success(),empty_text_fields();
		 * else we call next_screen_faild( delete_user_controler.get_msg());	
		 * delete_user_controler.get_msg(); return the msg from the controller with all
		 * the error msg.
		 */
		JButton btnDelete = new JButton("delete");
		btnDelete.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if (!textField_id.getText().equals(""))
				{
					Delete_User_controler delete_user_controler=new Delete_User_controler();
					
					if(delete_user_controler.delete_User( textField_id.getText()))
					{
						next_screen_success();
						empty_text_fields();
						
					}
					else {
	
						next_screen_faild(delete_user_controler.get_msg());

					}
	
				}
				else
					error_msg();
				

			}
					
			
		});
		btnDelete.setFont(new Font("Tahoma", Font.PLAIN, 14));
		btnDelete.setBounds(482, 322, 89, 35);
		add(btnDelete);
		/*
		 *  btnBack ;When you click this button you will return to 
		 *  Sign_in_panel screen
		 */
		JButton btnBack = new JButton("back");
		btnBack.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				Sign_in_panel sip=new Sign_in_panel();
				on_screen_unload();
				BusinessImplements.GetInstance().getMainFrame().setContentPane(sip);
				sip.setSize(getMaximumSize());
				sip.on_screen_load();

			}
		});
		btnBack.setFont(new Font("Tahoma", Font.PLAIN, 14));
		btnBack.setBounds(48, 322, 89, 35);
		add(btnBack);

	}

	@Override
	public void next_screen() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void prev_screen() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void on_screen_load() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void on_screen_unload() {
		// TODO Auto-generated method stub
		
	}
	/**
	 * this method display showMessageDialog with a failed msg
	 */
	public void error_msg()
	{
	JOptionPane.showMessageDialog(this,"miss author deatails ");
	}
	/**
	 * this method display showMessageDialog with a success msg
	 */
	public void next_screen_success()
	{
		JOptionPane.showMessageDialog(this,"delete success");
	}
	/**
	 * this method display showMessageDialog with a failed msg
	 * @param msg
	 */
	public void next_screen_faild(String msg)
	{
		JOptionPane.showMessageDialog(this,"delete faild "+msg);
	}
	/**
	 * this method initially the panel
	 */
	public void empty_text_fields()
	{
		textField_id.setText(null);
		
	}

}
